package cn.org.eshow.webapp.action.response;


import cn.org.eshow.model.Product;
import cn.org.eshow.util.StringUtil;

import java.util.Date;
import java.util.List;

/**
 * 商品返回对象
 */
public class ProductResponse {
    public Integer id;//商品ID
    public Date addTime = new Date();// 添加时间
    public Date updateTime = new Date();// 更新时间
    public String category = "";// 分类
    public String name = "";// 商品名称
    public String style;// 风格
    public Integer age;// 年龄段（1,0-20   2,21-40  3,41-60）
    public Double price = 0.00;// 单价
    public Double marketPrice = 0.00;// 市场价
    public Integer monthSales = 0;// 月销量
    public String img = "";//主图片
    public String imgs = "";//图片地址(逗号隔开)
    public String description;//描述
    public String content;//药品简介
    public Integer count = 0;//评论次数
    public Integer favoriteSize = 0;//收藏数
    public Integer state = 1;//状态（1上架，0下架）
    public Boolean ifDiscount = Boolean.FALSE;// 是否限时打折
    public Double discount;//折扣
    public Integer goodComment = 0;// 好评数
    public Integer middleComment = 0;// 中评数
    public Integer badComment = 0;// 差评数
    public Double ratio = 0.00;// 好评率
    public Boolean ifFavorite = false;//是否收藏
    public List<ProductItemResponse> productItems;//详细商品列表


    public ProductResponse() {
    }

    public ProductResponse(Product product) {
        this.id = product.getId();
        this.addTime = product.getAddTime();
        this.updateTime = product.getUpdateTime();
        this.category = product.getCategory() == null ? "" : product.getCategory();
        this.name = product.getName();
        this.style = product.getStyle();
        this.age = product.getAge();
        this.price = product.getPrice();
        this.marketPrice = product.getMarketPrice();
        this.monthSales = product.getMonthSales();
        this.img = product.getImg() == null ? "" : product.getImg();
        this.imgs = product.getImgs() == null ? "" : product.getImgs();
        this.description = product.getDescription() == null ? "" : product.getDescription();
        this.content = product.getContent() == null ? "" : product.getContent();
        this.count = product.getCount();
        this.favoriteSize = product.getFavoriteSize();
        this.state = product.getState();
        this.ifDiscount = product.getIfDiscount();
        this.discount = product.getDiscount();
        this.goodComment = (product.getGoodComment() == null ? 0 : product.getGoodComment());
        this.middleComment = (product.getMiddleComment() == null ? 0 : product.getMiddleComment());
        this.badComment = (product.getBadComment() == null ? 0 : product.getBadComment());
        double total = (double) (this.goodComment + this.middleComment + this.badComment);
        if (total > 0) {
            this.ratio = StringUtil.toDecimal(this.goodComment / total, 4);
        }
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public Integer getMonthSales() {
        return monthSales;
    }

    public void setMonthSales(Integer monthSales) {
        this.monthSales = monthSales;
    }


    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public String getImgs() {
        return imgs;
    }

    public void setImgs(String imgs) {
        this.imgs = imgs;
    }


    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public Integer getFavoriteSize() {
        return favoriteSize;
    }

    public void setFavoriteSize(Integer favoriteSize) {
        this.favoriteSize = favoriteSize;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Boolean getIfDiscount() {
        return ifDiscount;
    }

    public void setIfDiscount(Boolean ifDiscount) {
        this.ifDiscount = ifDiscount;
    }

    public Double getDiscount() {
        return discount;
    }

    public void setDiscount(Double discount) {
        this.discount = discount;
    }

    public String getStyle() {
        return style;
    }

    public void setStyle(String style) {
        this.style = style;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Double getMarketPrice() {
        return marketPrice;
    }

    public void setMarketPrice(Double marketPrice) {
        this.marketPrice = marketPrice;
    }

    public Integer getGoodComment() {
        return goodComment;
    }

    public void setGoodComment(Integer goodComment) {
        this.goodComment = goodComment;
    }

    public Integer getMiddleComment() {
        return middleComment;
    }

    public void setMiddleComment(Integer middleComment) {
        this.middleComment = middleComment;
    }

    public Integer getBadComment() {
        return badComment;
    }

    public void setBadComment(Integer badComment) {
        this.badComment = badComment;
    }

    public Double getRatio() {
        return ratio;
    }

    public void setRatio(Double ratio) {
        this.ratio = ratio;
    }

    public Boolean getIfFavorite() {
        return ifFavorite;
    }

    public void setIfFavorite(Boolean ifFavorite) {
        this.ifFavorite = ifFavorite;
    }

    public List<ProductItemResponse> getProductItems() {
        return productItems;
    }

    public void setProductItems(List<ProductItemResponse> productItems) {
        this.productItems = productItems;
    }
}